#include "popupmenu.h"

PopupMenu::PopupMenu(QWidget * parent) : KeyControllableMenu(parent)
{
    mainLayout=new QVBoxLayout();
    mainLayout->setSpacing(1);
    //setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    //setMinimumSize(QSize(300,100));
    //setStyleSheet("QWidget { background: rgba(0, 0, 0,255); color: rgb(255,255,255); border: 1px solid white; border-radius: 10px;}");
    setWindowFlags(Qt::WindowStaysOnTopHint| Qt::Dialog | Qt::FramelessWindowHint);
    setStyleSheet("background: rgb(0,0,0); color: rgb(255,255,255);");
    QString unSelectedStyleSheet="background: rgba(255, 255, 255, 15); border: 1px solid rgba(255, 255, 255, 0); text-align: left; color: white;";
    QString selectedStyleSheet="background: qlineargradient(spread:pad, x1:0.07, y1:0.153409, x2:1, y2:1, stop:0 rgba(0, 0, 0, 50), stop:1 rgba(255, 255, 255, 70)); color: white; text-align: left; border: 1px solid rgba(255, 255, 255, 200);";
    QString inactiveSelectedStyleSheet="background-color: grey; text-align: left; color: white;";
    setStyleSheets(selectedStyleSheet,unSelectedStyleSheet, inactiveSelectedStyleSheet);
    setWindowOpacity(0.75);
    setLayout(mainLayout);
}

void PopupMenu::addButton(Button * button) {
    KeyControllableMenu::addRow(button);
    mainLayout->addWidget(button,0,Qt::AlignTop|Qt::AlignLeft);
    setMinimumHeight(minimumHeight()+50);
}

void PopupMenu::addButtons(QList<Button *> * buttons) {
    foreach(Button * button, *buttons) {
        addButton(button);
    }
}

void PopupMenu::buttonSelected() {
    hide();
    emit selected(getCurrentButton());
}
